﻿<%@ Page Title="" Language="C#" MasterPageFile="~/admin/Admin-One-Column.master" AutoEventWireup="true" CodeBehind="QuanLiSach.aspx.cs" Inherits="BookStore.admin.QuanLiSach" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="BreadcrumbsContent" runat="server">
<h1>Quản Lí Sách</h1>
<br />
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="MainColumnContent" runat="server">
Nhấn vào tên sách để chỉnh sửa được nhiều thông tin hơn
<br />
<br />
    <div id="admin-table">
        <asp:GridView ID="QuanLiSachGV" runat="server" AllowPaging="True" 
        AutoGenerateColumns="False" DataKeyNames="MaSach" DataSourceID="QuanLiSachDS" 
            PageSize="5" CellPadding="4" ForeColor="#333333" GridLines="None">
            <AlternatingRowStyle CssClass="alt-row" BackColor="White" />
            <Columns>
                <asp:TemplateField SortExpression="ImageURL">
                    <EditItemTemplate>
                        <asp:TextBox CssClass="input-text" ID="TextBox7" runat="server" Text='<%# Bind("ImageURL") %>'></asp:TextBox>
                        <asp:HiddenField ID="HiddenField1" Value='<%# Bind("MaLoaiSach") %>' runat="server" />
                        <asp:HiddenField ID="HiddenField2" Value='<%# Bind("MaNXB") %>' runat="server" />
                        <asp:HiddenField ID="HiddenField3" Value='<%# Bind("NgayXuatBan") %>' runat="server" />
                        <asp:HiddenField ID="HiddenField4" Value='<%# Bind("ChieuCao") %>' runat="server" />
                        <asp:HiddenField ID="HiddenField5" Value='<%# Bind("ChieuRong") %>' runat="server" />
                        <asp:HiddenField ID="HiddenField6" Value='<%# Bind("BeDay") %>' runat="server" />
                        <asp:HiddenField ID="HiddenField7" Value='<%# Bind("KhoiLuong") %>' runat="server" />
                    </EditItemTemplate>
                    <ItemTemplate>
                        <asp:Image Width="80" ID="Image1" ImageUrl='<%# "." + Eval("ImageURL") %>' runat="server" />
                        <asp:HiddenField ID="HiddenField1" Value='<%# Bind("MaLoaiSach") %>' runat="server" />
                        <asp:HiddenField ID="HiddenField2" Value='<%# Bind("MaNXB") %>' runat="server" />
                        <asp:HiddenField ID="HiddenField3" Value='<%# Bind("NgayXuatBan") %>' runat="server" />
                        <asp:HiddenField ID="HiddenField4" Value='<%# Bind("ChieuCao") %>' runat="server" />
                        <asp:HiddenField ID="HiddenField5" Value='<%# Bind("ChieuRong") %>' runat="server" />
                        <asp:HiddenField ID="HiddenField6" Value='<%# Bind("BeDay") %>' runat="server" />
                        <asp:HiddenField ID="HiddenField7" Value='<%# Bind("KhoiLuong") %>' runat="server" />
                    </ItemTemplate>
                    <ItemStyle Width="100px" />
                </asp:TemplateField>
            <asp:TemplateField HeaderText="Tên Sách" SortExpression="TenSach">
                <EditItemTemplate>
                    <asp:TextBox CssClass="input-text" ID="TextBox3" runat="server" Text='<%# Bind("TenSach") %>'></asp:TextBox>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:HyperLink ID="HyperLink1" NavigateUrl='<%# "./Sach.aspx?id=" + Eval("MaSach") %>' runat="server" Text='<%# Bind("TenSach") %>'>HyperLink</asp:HyperLink>
                </ItemTemplate>
            </asp:TemplateField>

            <asp:TemplateField HeaderText="Mô Tả" SortExpression="Mota">
                <EditItemTemplate>
                    <asp:TextBox CssClass="input-text" ID="TextBox4" runat="server" Text='<%# Bind("Mota") %>' TextMode="MultiLine"></asp:TextBox>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="Label5" runat="server" Text='<%# Bind("Mota") %>'></asp:Label>
                </ItemTemplate>
                <ItemStyle Width="370px" />
            </asp:TemplateField>

            <asp:TemplateField HeaderText="Số Lượng" SortExpression="SoLuong">
                <EditItemTemplate>
                    <asp:TextBox CssClass="input-text" ID="TextBox5" runat="server" Text='<%# Bind("SoLuong") %>'></asp:TextBox>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="Label6" runat="server" Text='<%# Bind("SoLuong") %>'></asp:Label>
                </ItemTemplate>
                <ItemStyle Width="90px" />
            </asp:TemplateField>

            <asp:TemplateField HeaderText="Giá" SortExpression="DonGia">
                <EditItemTemplate>
                    <asp:TextBox CssClass="input-text" ID="TextBox6" runat="server" Text='<%# Bind("DonGia") %>'></asp:TextBox>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="Label7" runat="server" Text='<%# Bind("DonGia") %>'></asp:Label>
                </ItemTemplate>
                <ItemStyle Width="70px" />
            </asp:TemplateField>

            <asp:TemplateField ShowHeader="False">
                <EditItemTemplate>
                    <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="True" 
                        CommandName="Update" Text=""><img alt="Delete" src="../images/check.png"></asp:LinkButton>
                    &nbsp;<asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" 
                        CommandName="Cancel" Text=""><img alt="Delete" src="../images/cross.png"></asp:LinkButton>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" 
                        CommandName="Edit" Text=""><img alt="Edit" src="../images/pencil.png"></asp:LinkButton>
                    &nbsp;<asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" 
                        CommandName="Delete" Text=""><img alt="Delete" src="../images/cross.png"></asp:LinkButton>
                </ItemTemplate>
                <ItemStyle Width="45px" />
            </asp:TemplateField>
        </Columns>
        
            <EditRowStyle CssClass="align-top" BackColor="#7C6F57" />
            <FooterStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
            <HeaderStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
            <PagerStyle CssClass="pagination" BackColor="#666666" ForeColor="White" 
                HorizontalAlign="Center" />
            
            <RowStyle BackColor="#E3EAEB" />
            <SelectedRowStyle BackColor="#C5BBAF" Font-Bold="True" ForeColor="#333333" />
            <SortedAscendingCellStyle BackColor="#F8FAFA" />
            <SortedAscendingHeaderStyle BackColor="#246B61" />
            <SortedDescendingCellStyle BackColor="#D4DFE1" />
            <SortedDescendingHeaderStyle BackColor="#15524A" />
            
    </asp:GridView>

    <asp:SqlDataSource ID="QuanLiSachDS" runat="server" 
        ConnectionString="<%$ ConnectionStrings:BookStoreConnectionString %>" 
        DeleteCommand="DELETE FROM [Sach] WHERE [MaSach] = @MaSach" 
        InsertCommand="INSERT INTO [Sach] ([MaLoaiSach], [MaNXB], [TenSach], [NgayXuatBan], [Mota], [SoLuong], [DonGia], [ImageURL], [ChieuCao], [ChieuRong], [BeDay], [KhoiLuong]) VALUES (@MaLoaiSach, @MaNXB, @TenSach, @NgayXuatBan, @Mota, @SoLuong, @DonGia, @ImageURL, @ChieuCao, @ChieuRong, @BeDay, @KhoiLuong)" 
        SelectCommand="SELECT * FROM [Sach]" 
        UpdateCommand="UPDATE [Sach] SET [MaLoaiSach] = @MaLoaiSach, [MaNXB] = @MaNXB, [TenSach] = @TenSach, [NgayXuatBan] = @NgayXuatBan, [Mota] = @Mota, [SoLuong] = @SoLuong, [DonGia] = @DonGia, [ImageURL] = @ImageURL, [ChieuCao] = @ChieuCao, [ChieuRong] = @ChieuRong, [BeDay] = @BeDay, [KhoiLuong] = @KhoiLuong WHERE [MaSach] = @MaSach">
        <DeleteParameters>
            <asp:Parameter Name="MaSach" Type="Int32" />
        </DeleteParameters>
        <InsertParameters>
            <asp:Parameter Name="MaLoaiSach" Type="Int32" />
            <asp:Parameter Name="MaNXB" Type="Int32" />
            <asp:Parameter Name="TenSach" Type="String" />
            <asp:Parameter Name="NgayXuatBan" Type="DateTime" />
            <asp:Parameter Name="Mota" Type="String" />
            <asp:Parameter Name="SoLuong" Type="Int32" />
            <asp:Parameter Name="DonGia" Type="Int32" />
            <asp:Parameter Name="ImageURL" Type="String" />
            <asp:Parameter Name="ChieuCao" Type="Int32" />
            <asp:Parameter Name="ChieuRong" Type="Int32" />
            <asp:Parameter Name="BeDay" Type="Int32" />
            <asp:Parameter Name="KhoiLuong" Type="Int32" />
        </InsertParameters>
        <UpdateParameters>
            <asp:Parameter Name="MaLoaiSach" Type="Int32" />
            <asp:Parameter Name="MaNXB" Type="Int32" />
            <asp:Parameter Name="TenSach" Type="String" />
            <asp:Parameter Name="NgayXuatBan" Type="DateTime" />
            <asp:Parameter Name="Mota" Type="String" />
            <asp:Parameter Name="SoLuong" Type="Int32" />
            <asp:Parameter Name="DonGia" Type="Int32" />
            <asp:Parameter Name="ImageURL" Type="String" />
            <asp:Parameter Name="ChieuCao" Type="Int32" />
            <asp:Parameter Name="ChieuRong" Type="Int32" />
            <asp:Parameter Name="BeDay" Type="Int32" />
            <asp:Parameter Name="KhoiLuong" Type="Int32" />
            <asp:Parameter Name="MaSach" Type="Int32" />
        </UpdateParameters>
    </asp:SqlDataSource>
    <div style="border:1px solid #ccc;margin:20px;border-radius:5px;width:400px;float:left;">
        <asp:GridView ShowHeaderWhenEmpty="True" ID="LoaiSachGV" runat="server" AllowPaging="True" 
            AutoGenerateColumns="False" DataKeyNames="MaLoaiSach" Style="width:400px;"
            DataSourceID="LoaiSachGVDS" CellPadding="4" ForeColor="#333333" 
            GridLines="None" PageSize="5">
            <AlternatingRowStyle CssClass="alt-row" BackColor="White" />
            <Columns>
                <asp:TemplateField HeaderText="Mã" InsertVisible="False" 
                    SortExpression="MaLoaiSach">
                    <EditItemTemplate>
                        <asp:Label ID="Label1" runat="server" Text='<%# Eval("MaLoaiSach") %>'></asp:Label>
                    </EditItemTemplate>
                    <ItemTemplate>
                        <asp:Label ID="Label2" runat="server" Text='<%# Bind("MaLoaiSach") %>'></asp:Label>
                    </ItemTemplate>
                    <ItemStyle Width="20px" />
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Tên Loại Sách" SortExpression="TenLoaiSach">
                    <EditItemTemplate>
                        <asp:TextBox CssClass="input-text" ID="TextBox1" runat="server" Text='<%# Bind("TenLoaiSach") %>'></asp:TextBox>
                    </EditItemTemplate>
                    <ItemTemplate>
                        <asp:Label ID="Label1" runat="server" Text='<%# Bind("TenLoaiSach") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField ShowHeader="False">
                    <EditItemTemplate>
                        <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="True" 
                            CommandName="Update" Text=""><img alt="Delete" src="../images/check.png"></asp:LinkButton>
                        &nbsp;<asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" 
                            CommandName="Cancel" Text=""><img alt="Delete" src="../images/cross.png"></asp:LinkButton>
                    </EditItemTemplate>
                    <ItemTemplate>
                        <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" 
                            CommandName="Edit" Text="Edit"><img alt="Edit" src="../images/pencil.png"></asp:LinkButton>
                        &nbsp;<asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" 
                            CommandName="Delete" Text=""><img alt="Delete" src="../images/cross.png"></asp:LinkButton>
                    </ItemTemplate>
                    <ItemStyle Width="40px" />
                </asp:TemplateField>
            </Columns>
            <EditRowStyle CssClass="align-top" BackColor="#7C6F57" />
            <FooterStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
            <HeaderStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
            <PagerStyle CssClass="pagination" BackColor="#666666" ForeColor="White" 
                HorizontalAlign="Center" />
            <RowStyle BackColor="#E3EAEB" />
            <SelectedRowStyle BackColor="#C5BBAF" Font-Bold="True" ForeColor="#333333" />
            <SortedAscendingCellStyle BackColor="#F8FAFA" />
            <SortedAscendingHeaderStyle BackColor="#246B61" />
            <SortedDescendingCellStyle BackColor="#D4DFE1" />
            <SortedDescendingHeaderStyle BackColor="#15524A" />
        </asp:GridView>
        <asp:SqlDataSource ID="LoaiSachGVDS" runat="server" 
            ConflictDetection="CompareAllValues" 
            ConnectionString="<%$ ConnectionStrings:BookStoreConnectionString %>" 
            DeleteCommand="DELETE FROM [LoaiSach] WHERE [MaLoaiSach] = @original_MaLoaiSach AND (([TenLoaiSach] = @original_TenLoaiSach) OR ([TenLoaiSach] IS NULL AND @original_TenLoaiSach IS NULL))" 
            InsertCommand="INSERT INTO [LoaiSach] ([TenLoaiSach]) VALUES (@TenLoaiSach)" 
            OldValuesParameterFormatString="original_{0}" 
            SelectCommand="SELECT * FROM [LoaiSach]" 
            UpdateCommand="UPDATE [LoaiSach] SET [TenLoaiSach] = @TenLoaiSach WHERE [MaLoaiSach] = @original_MaLoaiSach AND (([TenLoaiSach] = @original_TenLoaiSach) OR ([TenLoaiSach] IS NULL AND @original_TenLoaiSach IS NULL))">
            <DeleteParameters>
                <asp:Parameter Name="original_MaLoaiSach" Type="Int32" />
                <asp:Parameter Name="original_TenLoaiSach" Type="String" />
            </DeleteParameters>
            <InsertParameters>
                <asp:Parameter Name="TenLoaiSach" Type="String" />
            </InsertParameters>
            <UpdateParameters>
                <asp:Parameter Name="TenLoaiSach" Type="String" />
                <asp:Parameter Name="original_MaLoaiSach" Type="Int32" />
                <asp:Parameter Name="original_TenLoaiSach" Type="String" />
            </UpdateParameters>
        </asp:SqlDataSource>
        </div>
        <div style="float:right;width:300px;margin:20px;margin-right:196px;">
        <asp:FormView ID="LoaiSachMoi" runat="server" DataKeyNames="MaLoaiSach" DefaultMode="Insert"
                DataSourceID="LoaiSachMoiDS" oniteminserted="LoaiSachMoi_ItemInserted">
            <EditItemTemplate>
                MaLoaiSach:
                <asp:Label ID="MaLoaiSachLabel1" runat="server" 
                    Text='<%# Eval("MaLoaiSach") %>' />
                <br />
                TenLoaiSach:
                <asp:TextBox ID="TenLoaiSachTextBox" runat="server" 
                    Text='<%# Bind("TenLoaiSach") %>' />
                <br />
                <asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True" 
                    CommandName="Update" Text="Update" />
                &nbsp;<asp:LinkButton ID="UpdateCancelButton" runat="server" 
                    CausesValidation="False" CommandName="Cancel" Text="Cancel" />
            </EditItemTemplate>
            <InsertItemTemplate>
            <h4>Thêm Loại Sách mới</h4>
            <br />
                Tên Loại Sách:
                <asp:TextBox Style="margin:5px 0px;" CssClass="input-text" ID="TenLoaiSachTextBox" runat="server" 
                    Text='<%# Bind("TenLoaiSach") %>' />
                <br />
                <asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True" 
                    CommandName="Insert" Text="Insert" />
                &nbsp;<asp:LinkButton ID="InsertCancelButton" runat="server" 
                    CausesValidation="False" CommandName="Cancel" Text="Cancel" />
            </InsertItemTemplate>
            <ItemTemplate>
                MaLoaiSach:
                <asp:Label ID="MaLoaiSachLabel" runat="server" 
                    Text='<%# Eval("MaLoaiSach") %>' />
                <br />
                TenLoaiSach:
                <asp:Label ID="TenLoaiSachLabel" runat="server" 
                    Text='<%# Bind("TenLoaiSach") %>' />
                <br />
                <asp:LinkButton ID="EditButton" runat="server" CausesValidation="False" 
                    CommandName="Edit" Text="Edit" />
                &nbsp;<asp:LinkButton ID="DeleteButton" runat="server" CausesValidation="False" 
                    CommandName="Delete" Text="Delete" />
                &nbsp;<asp:LinkButton ID="NewButton" runat="server" CausesValidation="False" 
                    CommandName="New" Text="New" />
            </ItemTemplate>
        </asp:FormView>
            <asp:SqlDataSource ID="LoaiSachMoiDS" runat="server" 
                ConflictDetection="CompareAllValues" 
                ConnectionString="<%$ ConnectionStrings:BookStoreConnectionString %>" 
                DeleteCommand="DELETE FROM [LoaiSach] WHERE [MaLoaiSach] = @original_MaLoaiSach AND (([TenLoaiSach] = @original_TenLoaiSach) OR ([TenLoaiSach] IS NULL AND @original_TenLoaiSach IS NULL))" 
                InsertCommand="INSERT INTO [LoaiSach] ([TenLoaiSach]) VALUES (@TenLoaiSach)" 
                OldValuesParameterFormatString="original_{0}" 
                SelectCommand="SELECT * FROM [LoaiSach]" 
                UpdateCommand="UPDATE [LoaiSach] SET [TenLoaiSach] = @TenLoaiSach WHERE [MaLoaiSach] = @original_MaLoaiSach AND (([TenLoaiSach] = @original_TenLoaiSach) OR ([TenLoaiSach] IS NULL AND @original_TenLoaiSach IS NULL))">
                <DeleteParameters>
                    <asp:Parameter Name="original_MaLoaiSach" Type="Int32" />
                    <asp:Parameter Name="original_TenLoaiSach" Type="String" />
                </DeleteParameters>
                <InsertParameters>
                    <asp:Parameter Name="TenLoaiSach" Type="String" />
                </InsertParameters>
                <UpdateParameters>
                    <asp:Parameter Name="TenLoaiSach" Type="String" />
                    <asp:Parameter Name="original_MaLoaiSach" Type="Int32" />
                    <asp:Parameter Name="original_TenLoaiSach" Type="String" />
                </UpdateParameters>
            </asp:SqlDataSource>
    </div>
    </div>
</asp:Content>
